package com.xyht.sca_s.student_manage_system.modules.assetFixedDepreciation.controller;


import com.xyht.sca_s.student_manage_system.auth.util.JwtTokenUtil;
import com.xyht.sca_s.student_manage_system.common.commonReturn.CommonCodeEnum;
import com.xyht.sca_s.student_manage_system.common.commonReturn.CommonResult;
import com.xyht.sca_s.student_manage_system.common.commonReturn.ResponseResult;
import com.xyht.sca_s.student_manage_system.common.desEncodeAndDecode.annotation.SecretBody;
import com.xyht.sca_s.student_manage_system.modules.asset.entity.req.SmsAssetFixedStorageExportReq;
import com.xyht.sca_s.student_manage_system.modules.assetFixedDepreciation.service.SmsAssetFixedDepreciationTaskService;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.concurrent.Future;

/**
 * <p>
 * 资产折旧任务表 前端控制器
 * </p>
 *
 * @author XYHT
 * @since 2024-10-10
 */
@RestController
@RequestMapping("/assetFixed/depreciation")
@SecretBody
public class SmsAssetFixedDepreciationTaskController {
    @Resource
    private SmsAssetFixedDepreciationTaskService smsAssetFixedDepreciationTaskService;
    @Resource
    private JwtTokenUtil jwtTokenUtil;

    @ApiOperation(value = "折旧数据更新")
    @PostMapping("/update")
    public ResponseResult updateAllAsset(HttpServletRequest request) {
        String user_id = jwtTokenUtil.getUserIdByRequest(request);
        ResponseResult commonCodeEnum;
        try {
            Future<ResponseResult> future = smsAssetFixedDepreciationTaskService.updateAllAsset(user_id);
            while (true) {
                if (future.isDone()) {
                    commonCodeEnum = future.get();
                    break;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            return CommonResult.failed(CommonCodeEnum.FAIL);
        }
        return commonCodeEnum;
    }

    @ApiOperation(value = "折旧更新任务列表")
    @GetMapping("/taskList")
    public ResponseResult getTaskInfoList(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                          @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        return smsAssetFixedDepreciationTaskService.getTaskInfoList(pageNum, pageSize);
    }

    @ApiOperation(value = "折旧更新任务详情列表")
    @GetMapping("/detailList")
    public ResponseResult getTaskDetailList(@RequestParam(value = "taskId") String taskId,
                                         @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                         @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        return smsAssetFixedDepreciationTaskService.getTaskDetailList(taskId,pageNum, pageSize);
    }

}

